package com.itheima.bank.dao;

import com.itheima.bank.domain.Account;
import com.itheima.bank.domain.Trade;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface BankDao {
    /**
     * 验证用户登陆
     */
    @Select("select * from account where accountid = #{accountid} and password = #{password}")
    public Account userLogin(Account account);

    /**
     * 查询用户是否存在
     */
    @Select("select * from account where accountid = #{id}")
    public Account selectUser(String accountid);

    /**
     * 查询用户余额
     */
    @Select("select remaining from account where accountid = #{id}")
    public Double selectRemaining(String accountid);

    /**
     * 查询用户交易记录
     */
    @Select("SELECT * FROM trade WHERE AccountID = #{accountid} AND  tradetime BETWEEN #{startTime} AND #{endTime}")
    public List<Trade> selectTrade(@Param("accountid") String accountid,
                                   @Param("startTime") String startTime,
                                   @Param("endTime") String endTime);

    /**
     * 给用户存取钱
     */
    @Select("update account set remaining = remaining + #{money} where accountid = #{accountid}")
    public void transMoney(@Param("accountid") String accountid, @Param("money") Double money);

    /**
     * 添加交易记录
     */
    @Insert("INSERT INTO trade VALUES (NULL,#{accountId},#{tradeType},#{tradeMoney},#{tradeTime},#{tradeDigest})")
    public void addTrade(Trade trade);
}